var Promise = require('./es6-promise.auto.js');
const requestHandler = require('./requestHandler.js');
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

let checkRegister = function(data){
  for(var k in data){
    if (data[k] === "" || data[k] === null) {
      wx.showModal({
        title: '提示',
        content: '存在未填选择，请检查！',
        confirmColor: '#118EDE',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            //console.log('用户点击确定')    
          }
        }
      });
      break;
      return false;
    }else{
      return true;
    }
  } 
}

let getDegreeIndex = function(degree){
  var arr_degree = { 
    '专科': 0, 
    '本科': 1, 
    '硕士': 2, 
    '博士': 3, 
    '博士后': 4 
    }
  var ret_val = 0
  for (var d in arr_degree){
    if (d==degree){
      ret_val = arr_degree[d];
      break;
    }
  }
  return ret_val;
}

let get_persion_img = function(query_id,data){
    var ret_data = {}
    if (data) {
      for (var d in data) {
        if (d) {
          for (var d_in in d) {
            if (d_in) {
              var src = '';
              requestHandler.sendRequest(d_in.file_name).then(values => {
                console.log('values.data====='+values)
                // d_in['src'] = values;
              });
            }
          }
        }
      }
    }
  return ret_data;
}

module.exports = {
  formatTime: formatTime,
  checkRegister: checkRegister,
  getDegreeIndex: getDegreeIndex,
  get_persion_img: get_persion_img
}
